/************************************************************************************************
 * test examples of 100 interesting program in C
 * test 015.c
 * Fisher and Fishes
 ***********************************************************************************************/

#include <stdio.h>

/*
 * an example of reverse inference
 */

int main()
{
    int i = 0;
    // fishes remain for last fisher is 5n+1, start reverse inference
    for (i = 6; ; i += 5)
    {
        int j = 0;
        int flag = 1;
        int x = 0;
        // be caution, the 5th fisher need not to be examined bcz there's no 6th one.
        // so the loop is [1, 5).
        for (x = i, j = 1; (flag && (j < 5)); j++)
        {
            if (x%4 == 0)
                x = x/4*5 + 1;
            else
                flag = 0;
        }
        if (flag)
        {
            printf("Total can be %d\n", x);
            break;
        }
    }
}

